package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import android.util.Log;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.Account;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.GmailSender;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.ForgotAccountView;

/**
 * Presenter for the forgot account functionality
 * @author Magic 7
 *
 */
public class ForgotAccountPresenter {
	private ForgotAccountView myView;
	private String password;
	private DatabaseHelper helper;
	
	/**
	 * Constructor for this class
	 * @param myView the view of the screen
	 */

	public ForgotAccountPresenter(ForgotAccountView myView) {
		myView = this.myView;
		helper = new DatabaseHelper(myView);
	}

	/**
	 * This is supposed to send an email
	 * 
	 * @param emailAddress
	 */
	public void sendEmail(String emailAddress) {
		getAccountAndPassword(emailAddress);
		
		try {   
            GmailSender sender = new GmailSender("cs2340magic7@gmail.com", "test12345678");
            sender.sendMail("Here is the password you forgot, dummy!",  //subject 
                    "Your password is: " + password, //body
                    "user@gmail.com",   //sender
                    emailAddress);  //recipient
        } catch (Exception e) {   
            Log.e("SendMail", e.getMessage(), e);   
        } 
		
		/*
		getAccountAndPassword(emailAddress);
		String[] emailAddr = { emailAddress };
		String subject = "Where's My Stuff Forgot Password";
		Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
		emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailAddr);
		emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
		*/
		
		
	}

	/**
	 * This gets the account's password
	 * @param emailAddress
	 */
	private void getAccountAndPassword(String emailAddress) {
		Account account = helper.getAccount(emailAddress);
		password = account.getPassword();
	}

	/**
	 * This sets the body of the email message
	 * @param emailAddress the email address that is connected with the password to send out
	 * @return The message body of the email
	 */
	@SuppressWarnings("unused")
	private String setMessageBody(String emailAddress) {
		return "Here is the password for username " + emailAddress + '\n'
				+ password;
	}
}
